<template>
	<div>
		<LeftNav :currentPath="'deregister'"></LeftNav>

		<div class="mywz_publish margin_auto justify_content_sb mine_content_right">
			<div class="deregister_header_title">注销您的MetaEra账号</div>
			<div class="deregister_content">
				<div class="deregister-notice">
					<h3>亲爱的用户，</h3>
					<p>
						感谢您使用MetaEra平台。我们理解您可能出于某种原因选择注销账号。在您决定之前，请仔细阅读以下信息：
					</p>

					<h4>1. 注销结果</h4>
					<ul>
						<li>
							注销账号后，您的所有个人信息、评论、收藏和历史记录将被永久删除，无法恢复；
						</li>
						<li> 一旦注销，您将无法使用相同的邮箱或用户名登陆MetaEra； </li>
						<li>
							作者文章处理：如果您是作者，您的文章将被保留并归拢至指定的MetaEra账户下，您注销后将无法再管理这些文章。如果文章也想全部删除，请联系content@metaera.hk，要求工作人员配合处理；
						</li>
						<li> 可以重新注册账号使用MetaEra的服务。 </li>
					</ul>
					<h4>2. 反馈与建议</h4>
					<p>
						我们非常重视用户的意见。如果您愿意，您可以在注销前提供您的反馈或建议，帮助我们改进服务。
					</p>

					<h4>3. 注销流程发起</h4>
					<p>
						我们会在您提交注销流程30天后自动执行流程，注销您的账号。若您在该期间使用该账号登录MetaEra则视为放弃注销流程，我们将会暂停注销行为。注销流程完成，我们会邮件通知您注销结果。
					</p>

					<p class="deregister-footer">感谢您一直以来的支持，祝您一切顺利！</p>
				</div>
				<div class="deregister_check">
					<div class="deregister_check_item">
						<img
							v-if="check1"
							@click="check1 = !check1"
							src="https://res.metaera.hk/resources/assets/images/web/复选框.png"
							class="pointer"
						/>
						<img
							v-else
							@click="check1 = !check1"
							src="https://res.metaera.hk/resources/assets/images/web/复选框 (1).png"
							class="pointer"
						/>
						<span>
							我已阅读并理解MetaEra账号注销须知，已知晓和确认发起注销流程的风险和后果。
						</span>
					</div>
					<divv class="deregister_check_item">
						<img
							v-if="check2"
							@click="check2 = !check2"
							src="https://res.metaera.hk/resources/assets/images/web/复选框.png"
							class="pointer"
						/>
						<img
							v-else
							@click="check2 = !check2"
							src="https://res.metaera.hk/resources/assets/images/web/复选框 (1).png"
							class="pointer"
						/>
						<span>
							我已确认发起账号邮箱为
							{{ email }}
							的账号注销流程</span
						>
					</divv>
				</div>
			</div>
			<div class="deregister_btn_content">
				<div class="deregister_btn">
					<div
						class="deregister_btn_item deregister_btn_item_submit"
						@click="submitDeregister()"
					>
						发起注销流程
					</div>
					<div class="deregister_btn_item" @click="closeDeregister()">取消</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import store from "@/store";
import Vue from "vue";
import { deregister } from "@/api/user";
import { newBus } from "@/components/pc/topHeader2.vue";
import {
	getToken,
	setToken,
	removeToken,
	setUserId,
	setUserMobile,
	removeUserMobile,
	removeUserId,
} from "@/utils/auth";

import LeftNav from "../leftNav";
export default {
	name: "",
	components: {
		LeftNav,
	},
	data() {
		return {
			email: this.$store.state.user.user.email,
			hasData: false,
			userInfo: {},
			localLanguage: 1,
			check1: false,
			check2: false,
		};
	},
	created() {
		const hasToken = getToken();
		console.log(hasToken);
		if (hasToken) {
			let localLanguage = sessionStorage.getItem("localLanguage");
			if (localLanguage == "繁体中文") {
				this.localLanguage = 1;
			} else if (localLanguage == "english") {
				this.localLanguage = 2;
			} else {
				this.localLanguage = 0;
			}
		} else {
			this.$router.push({ path: "/" });
		}
	},
	mounted() {
		newBus.$on("global-notification", (data) => {
			let localLanguage = sessionStorage.getItem("localLanguage");
			if (localLanguage == "繁体中文") {
				this.localLanguage = 1;
			} else if (localLanguage == "english") {
				this.localLanguage = 2;
			} else {
				this.localLanguage = 0;
			}
		});
		let localLanguage = sessionStorage.getItem("localLanguage");
		if (localLanguage == "繁体中文") {
			this.localLanguage = 1;
		} else if (localLanguage == "english") {
			this.localLanguage = 2;
		} else {
			this.localLanguage = 0;
		}
	},
	methods: {
		submitDeregister() {
			if (!this.check1 || !this.check2) {
				this.$message.error("请确认已阅读注销须知并同意相关条款");
				return;
			}

			deregister({})
				.then((res) => {
					if (res.code == 200) {
						removeToken(); // must remove  token  first
						removeUserId();
						removeUserMobile();
						this.$message.success("您的注销流程已发起");
						this.$router.push({ path: "/" });
					}
				})
				.catch((error) => {
					// this.$message.error(error.message);
				});
		},

		closeDeregister() {
			this.$router.push({ path: "/" });
		},
	},
};
</script>
<style scoped>
@import url("../../../assets/person.css");
.mywz_publish {
	border-radius: 20px;
	opacity: 1;
	box-shadow: 6.43px 21.04px 35px 0px rgba(54, 62, 147, 0.051);
	padding-left: 30px;
	padding-right: 30px;
	padding-top: 80px;
	padding-bottom: 30px;
}
.deregister_header_title {
	width: 100%;
	font-size: 24px;
	font-family: PingFang SC, "PingFang SC", "微软雅黑", "Helvetica Neue",
		"Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
	font-weight: 600;
	color: #fff;
	display: inline-block;
	align-content: center;
	align-items: center;
	text-align: center;
}
</style>

<style scoped>
.deregister-notice {
	color: #333;
	line-height: 1.6;
	padding: 20px;
	border-radius: 8px;
}

.deregister-notice h3 {
	font-size: 14px;
	margin-bottom: 10px;
	color: white;
}

.deregister-notice h4 {
	font-size: 14px;
	margin: 10px 0 10px;
	color: white;
}

.deregister-notice h5 {
	font-size: 14px;
	margin: 10px 0 8px;
	color: white;
}

.deregister-notice ul {
	font-size: 14px;
	padding-left: 20px;
	margin: 10px 0;
	color: white;
}

.deregister-notice p,
.deregister-notice li {
	font-size: 14px;
	margin: 10px 0;
	color: white;
}

.deregister-footer {
	font-size: 12px;
	margin-top: 10px;
	color: white;
}

.deregister_check {
	align-items: center;
	align-content: center;
	text-align: center;
}

.deregister_check_item {
	margin-bottom: 10px;
	display: flex;
	text-align: center;
	justify-content: center;
	align-items: center;
}

.deregister_check_item span {
	color: white;
	font-size: 16px;
	font-weight: 800px;
	margin-left: 6px;
}

.deregister_check_item img {
	width: 16px;
	height: 16px;
}
</style>
<style scoped>
.deregister_btn_content {
	margin-top: 50px;
	width: 100%;
	text-align: center;
	display: flex;
	justify-content: center;
}
.deregister_btn {
	display: flex;
	/* width: 300px; */
}
.deregister_btn_item {
	height: 40px;
	width: 160px;
	border-radius: 12px;
	font-size: 20px;
	color: white;
	background: #3d3d3d;
	align-content: center;
	/* padding: 0px 14px; */
	margin-right: 10px;
	margin-left: 10px;
}

.deregister_btn_item_submit {
	background: #ff4646;
}
</style>
